import re
from fuzzywuzzy import fuzz
from flask import Flask
from aip import AipOcr
import pymysql
import bwc_my_sql
import new_recognize
import new_judgement
if __name__ == '__main__':
    while True:
        with open('test.txt',mode='r',encoding='utf-8') as file_object:
            for line in file_object:
                line = line.strip()
                line = line.replace('"','').strip()
                # image = input('请输入目标url').strip()
                image = line
                data = {}
                clear_shoplist = list()
                count = 0
                getting = bwc_my_sql.Serve()
                result = getting.sql_serve(image)
                result = getting.getting_shop(result)
                content = new_recognize.recognization(image)
                # print(result)
                # print(content)
                method = new_judgement.Content(content)
                shopname = method.shopjudge()
                money = method.moneyjudge()
                number = method.dingdanjudge()
                # print(shopname)
                # print(money)
                # print(number)
                for shop in shopname:
                    similarity_ratio = fuzz.partial_ratio(shop, result[0])
                    if similarity_ratio >= 40:
                        clear_shoplist.append(result[0])
                        count = 1
                    clear_shoplist.append('null')
                data['shop_name'] = str(clear_shoplist[0])
                data['money'] = str(money[0])
                data['order_number'] = str(number[0])
                if count == 1 and data['shop_name']!='null':
                    data['result'] = '店铺识别成功'
                else:
                    data['result'] = '店铺识别失败'
                print(data)


